﻿#ifndef COMMON_TRIGGER_THREAD_H
#define COMMON_TRIGGER_THREAD_H

#include <QThread>
#include <QWeakPointer>
#include <libdaq/device/base_device.h>
using namespace libdaq::device;

class CommonTriggerADCThread : public QThread {
  Q_OBJECT
public:
  CommonTriggerADCThread(QSharedPointer<libdaq::device::LockzhinerBaseDevice> base_device);

signals:
  void SendData(const std::vector<std::vector<float> > &data);

public Q_SLOTS:
  void start(Priority = InheritPriority) ;
  void quit();

protected:
  void run() override;
  bool ReadADCData();
  bool CheckDataEmpty();
  bool CheckTimeout(const std::chrono::steady_clock::time_point &start, const int timeout_msec);  // 检查是否超时

protected:
  std::vector<std::vector<float> > data_;  // 存储读取的数据
  QWeakPointer<libdaq::device::LockzhinerBaseDevice> base_device_; // 设备示例
  std::atomic<bool> thread_is_running_ = false; // 线程是否运行
  uint32_t collect_data_length_ = 0; // 总数据长度
  int timeout_msec_ = 200; // 数据超时时间 单位：ms
};

#endif // COMMON_TRIGGER_THREAD_H
